<?php

namespace App\Console\Commands;


use Aitels\Design\DefinitionProcessor;
use Aitels\Design\Designer;
use Aitels\Design\ExcelDefinitionProvider;
use Aitels\Design\FileCacheStore;
use Aitels\Design\TableBuilder;
use Aitels\Design\TableManager;
use Illuminate\Console\Command;
use Modules\Common\Util\Database;


class DatabaseDesign extends Command
{

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'design';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * m@return mixed
     */
    public function handle()
    {
        ini_set('memory_limit', '2048M');
        $provider = new ExcelDefinitionProvider(base_path('database.xlsx'));
        //用户未定义字段默认值我们提供默认值
        $columnDefaults = [
            'integer' => Database::INT_DEFAULT,
            'string' => Database::STR_DEFAULT,
            'timestamp' => Database::TIMESTAMP_DEFAULT,
            'bool' => Database::BOOL_UNKNOWN,
            'decimal' => Database::DECIMAL_DEFAULT,
        ];
        $processor = new DefinitionProcessor($columnDefaults);
        $tableManger = new TableManager(new FileCacheStore(), new TableBuilder());
        $designer = new Designer($provider, $processor, $tableManger, $this);
        $designer->design();
        return 0;
    }
}
